<?php
include_only();

if(empty($search_text)){$search_text = "";}

$search = "
<center>
<form method='post' action='index.php'>
<input type='text' name='search_text' value='".$search_text."'/>
<select name='type'>
<option value='1'>subtitles</option>
<option value='2'>videos</option>
</select>
<input type='hidden' name='page' value='search' />
<input type='submit' value='search' />
</form>
</center>
";

if(!empty($type) and $type=='1' and !empty($search_text))
{
$search_subtitles = search_subtitles($search_text);
//print_r($search_subtitles);

$search = $search . "
<br>
<table style='width:100%'>
<tr>
<td>#</td>
<td>title</td>
<td>video</td>
<td>language</td>
</tr>
";

for ($i = 0; $i <= count($search_subtitles)-1; $i++) {
$count = $i + 1;
$lang = get_language_by_id($search_subtitles[$i]['language']);
$lang = $lang['name'];
$video_info = get_video_information($search_subtitles[$i]['video_id']);
$video_name = $video_info['name'];
$search = $search . "
<tr>
<td>".$count."</td>
<td>".$search_subtitles[$i]['title']."</td>
<td><center>".$video_name."</center></td>
<td><center>".$lang."</center></td>
</tr>
";
}

$search = $search . "
</table>
";
}



if(!empty($type) and $type=='2' and !empty($search_text))
{
$search_videos = search_videos($search_text);
//print_r($search_videos);

$search = $search . "
<br>
<table>
<tr>
<td>#</td>
<td>title</td>
<td>description</td>
</tr>
";

for ($i = 0; $i <= count($search_videos)-1; $i++) {
$count = $i + 1;
$search = $search . "
<tr>
<td>".$count."</td>
<td>".$search_videos[$i]['name']."</td>
<td>".$search_videos[$i]['desc']."</td>
</tr>
";
}

$search = $search . "
</table>
";
}
?>